
# event for main menu
from Shell.fsm.EventDefine import event_SINGLEPLAYER_NEWGAME, event_SINGLEPLAYER_LOADGAME, \
                                  event_SINGLEPLAYER_REPLY, event_SINGLEPLAYER_BACKTOMAINMENU
# skin
from Shell.gui.Skin import SkinGet
# gui
from Cube.gui.PreludeFinale import DropDownFrame
from direct.gui.DirectGui import DirectButton
from Cube.gui.DirectGUIPropertiesAccess import BtnTextSet, BtnCmdSet
from Cube.gui.QSizer import ResizedCallBackSet, BoxSizer, Spacer
from Cube.gui.DirectGUIPropertiesAccess import AlignText
# uiString
from Shell.data.UIString import uiString

class SinglePlayerGameMenuFrame(DropDownFrame):
    def __init__(self):
        DropDownFrame.__init__(self)

        ParameterDict = SkinGet("Single player game menu")

        param_sizerMain = ParameterDict["main sizer"]
        param_btn = ParameterDict["btn"]
        param_btn["parent"] = self

        # single player
        param_btn["text"] = uiString["New Game"]
        btn_NewGame = DirectButton(**param_btn )
        # network
        param_btn["text"] = uiString["Load Game"]
        btn_LoadGame = DirectButton(**param_btn )
        # Configure
        param_btn["text"] = uiString["Replay"]
        btn_Replay = DirectButton(**param_btn )
        # creator
        param_btn["text"] = uiString["Back"]
        btn_Back = DirectButton(**param_btn )

        BtnCmdSet(btn_NewGame, messenger.send, [event_SINGLEPLAYER_NEWGAME])
        BtnCmdSet(btn_LoadGame, messenger.send, [event_SINGLEPLAYER_LOADGAME])
        BtnCmdSet(btn_Replay, messenger.send, [event_SINGLEPLAYER_REPLY])
        BtnCmdSet(btn_Back, messenger.send, [event_SINGLEPLAYER_BACKTOMAINMENU])
        # add gui object into sizer
        sizerMain = BoxSizer(BoxSizer.VERTICAL,
                             gap = param_sizerMain["gap"],
                             size = param_sizerMain["size"])
        sizerMain.Add(btn_NewGame, 0)
        sizerMain.Add(btn_LoadGame, 0)
        sizerMain.Add(btn_Replay, 0)
        sizerMain.Add(Spacer(0.1), 0)
        sizerMain.Add(btn_Back, 0)
        # alignment gui object's text
        ResizedCallBackSet(btn_NewGame, AlignText, frame = btn_NewGame, align = "" )
        ResizedCallBackSet(btn_LoadGame, AlignText, frame = btn_LoadGame, align = "" )
        ResizedCallBackSet(btn_Replay, AlignText, frame = btn_Replay, align = "" )
        ResizedCallBackSet(btn_Back, AlignText, frame = btn_Back, align = "" )
        # do sizer layout
        sizerMain.Layout()

        self.Prelude()
